package com.lfk.justwetools.Utils;

import ohos.aafwk.ability.Ability;
import ohos.app.Context;
import ohos.aafwk.content.Intent;
import ohos.net.ConnectionProperties;
import ohos.net.NetManager;
import ohos.wifi.WifiDevice;

/**
 * 判断网络状态的工具类
 * @author liufengkai
 */
public class NetUtils {

    private NetUtils() {
		/* cannot be instantiated */
        throw new UnsupportedOperationException("cannot be instantiated");
    }

    /**
     * 判断网络是否连接
     * @param context
     * @return 是否已连接网络
     */
    public static boolean isConnected(Context context) {
        NetManager netManager = NetManager.getInstance(context);
        return netManager.hasDefaultNet();
    }

    /**
     * 判断是否是wifi连接
     * @param context
     * @return 是否连接Wi-Fi
     */
    public static boolean isWifi(Context context){
        // 先判断是否连接
        if (!isConnected(context)) {
            return false;
        }
        WifiDevice wifiDevice = WifiDevice.getInstance(context);
        return wifiDevice != null && wifiDevice.isConnected();
    }

    /**
     * 打开网络设置界面
     * @param ability
     */
    public static void openSetting(Ability ability) {
    }

    /**
     * 判断GPS是否打开
     *
     * @param context
     * @return
     */
    public static boolean isGpsEnabled(Context context) {
//        LocationManager alm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
//        if (!alm.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
//            return false;
//        }
        return true;
    }

}
